package com.xxgc.qiuqiu.config;


import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer;

/**
 * 长链接配置类
 */
@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {

    @Override
    public void configureMessageBroker(MessageBrokerRegistry registry) {
        //启动简单消息代理  订阅消息的开头必须佘/game
        registry.enableSimpleBroker("/game");
        //发送消息的开头 必须是/qiuqiu开头
        registry.setApplicationDestinationPrefixes("/qiuqiu");
    }

    @Override
    public void registerStompEndpoints(StompEndpointRegistry registry) {
        //注册 /ws 端点
        registry.addEndpoint("/ws").withSockJS();
    }
}
